package com.s.remotelog;

import android.content.Context;

import com.s.remotelog.rpc.RPCClient;
import com.s.remotelog.rpc.RPCEvent;

import s.log.Level;

public class RLog {

    private static boolean remoteLog = false;

    private RLog() {

    }

    public static void enableRemoteLog() {
        remoteLog = true;
    }

    public static void disableRemoteLog() {
        remoteLog = false;
    }

    /**
     * default is 500
     * @param max
     */
    public static void setMaxLogItems(int max) {
        RPCClient.getInstance().setMaxLogCache(max);
    }

    /**
     *  start connecting to the host phone.
     *
     * @param context
     * @param ssid  Host ap name, see in Settings
     * @param password Host ap password, see in Settings
     */
    public static void startLogging(Context context, String ssid, String password) {
        RPCClient.getInstance().start(context, ssid, password);
    }

    /**
     * exit logging to Host
     */
    public static void stopLogging() {
        RPCClient.getInstance().stop();
    }

    /**
     * info , the color is white
     * @param tag
     * @param msg
     */
    public static void i(String tag, String msg) {
        if (!remoteLog) {
            LocalLog.i(tag, msg);
            return;
        }
        RPCClient.getInstance().dispatchEvent(RPCEvent.make(Level.I_VALUE, tag, msg));
    }

    /**
     * debug , the color is green
     * @param tag
     * @param msg
     */
    public static void d(String tag, String msg) {
        if (!remoteLog) {
            LocalLog.d(tag, msg);
            return;
        }
        RPCClient.getInstance().dispatchEvent(RPCEvent.make(Level.D_VALUE, tag, msg));
    }

    /**
     * warning , the color is yellow
     * @param tag
     * @param msg
     */
    public static void w(String tag, String msg) {
        if (!remoteLog) {
            LocalLog.w(tag, msg);
            return;
        }
        RPCClient.getInstance().dispatchEvent(RPCEvent.make(Level.W_VALUE, tag, msg));
    }

    /**
     * error , the color is red
     * @param tag
     * @param msg
     */
    public static void e(String tag, String msg) {
        if (!remoteLog) {
            LocalLog.e(tag, msg);
            return;
        }
        RPCClient.getInstance().dispatchEvent(RPCEvent.make(Level.E_VALUE, tag, msg));
    }
}
